package com.ptp.backendcertms.basiccompnents.log;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StopWatch;


/**
 * 日志打印-计时包装器
 */
@Slf4j
public class WatchLogWrapper {

    /**
     * 日志包装打印
     *
     * @param key  打印的key
     * @param task 执行的任务
     */
    public static void watch(String key, Runnable task) {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        log.info("[WatchDogRunner]开始步骤{}.", key);
        try {
            task.run();
        } finally {
            stopWatch.stop();
            log.info("[WatchDogRunner]结束步骤{}.运行时间:{}ms.", key, stopWatch.getTotalTimeMillis());
        }
    }
}
